package com.kitkat.daoImpl;

import java.util.List;

import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.kitkat.dao.ProjectDAO;
import com.kitkat.entities.Project;

@Component
public class ProjectDAOImpl implements ProjectDAO{
	@Autowired
	private HibernateTemplate hibernateTemplate;
	
	@Override
	public void saveProject(Project project) {
		this.hibernateTemplate.save(project);
	}

	@Override
	public List<Project> getProjectByUserId(String userid) {
		Session session = this.hibernateTemplate.getSessionFactory().getCurrentSession();
		@SuppressWarnings("unchecked")
		List<Project> list = session.getNamedQuery("getProjectsByUserid")
								.setParameter("userid", userid)
								.list();
		return list;
	}

	@Override
	public Project getProjectById(String projectId) {
		Project project = this.hibernateTemplate.get(Project.class,projectId);
		return project;
	}

	@Override
	public void deleteProject(Project project) {
		this.hibernateTemplate.delete(project);
	}
	
}
